package com.Renting.controller;

import com.Renting.domain.Renting;
import com.Renting.domain.RentingUser;
import com.Renting.service.ServiceAdd;
import com.Renting.service.ServiceAdmin;
import com.Renting.service.ServiceGain;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class Admin {
    @Resource
    private ServiceAdd serviceAdd;
    @Resource
    private ServiceAdmin serviceAdmin;
    @Resource
    private ServiceGain gain;

    //添加新房间
    @PostMapping(value = "/AddRenting.do",produces = "text/html; charset=utf-8")
    public String AddRenting(Renting renting,HttpSession session){
        if(serviceAdd.AddRenting(renting)){
            session.setAttribute("AdminHint","添加成功");
            gain.GetRoomUser(session);
        }else{
            session.setAttribute("AdminHint","添加失败,编号已存在");
        }
        return "Admin-min";
    }

    //来到首页时,显示所有房间的信息
    @GetMapping(value = "/GetRoom.do",produces = "text/html; charset=utf-8")
    public String GetRoom(Renting renting, HttpSession session){

        serviceAdmin.AdminGetRoom(session,renting);
        return "Alter-min";
    }

    //来到User页面时候,显示所有用户信息
    @GetMapping(value = "/GetUser.do",produces = "text/html; charset=utf-8")
    public String GetUser(RentingUser rentingUser, HttpSession session){

        serviceAdmin.AdminGetUser(session,rentingUser);
        return "Alter-User";
    }

    //修改房间
    @PostMapping(value = "/AlterRoom.do",produces = "text/html; charset=utf-8")
    public String AlterRoom(Renting renting,HttpSession session){
        serviceAdmin.AdminAlterRoom(session,renting);
        return "Admin-min";
    }

    //修改用户
    @PostMapping(value = "/AlterUser.do",produces = "text/html; charset=utf-8")
    public String AlterUser(RentingUser rentingUser,HttpSession session){
        serviceAdmin.AdminAlterUser(session,rentingUser);
        return "Admin-User";
    }

    //删除房间
    @GetMapping(value = "/DeleteRoom.do",produces = "text/html; charset=utf-8")
    public String DeleteRoom(Renting renting,HttpSession session){
        serviceAdmin.AdminDeleteRoom(renting,session);
        return "Admin-min";
    }

    //删除用户
    @GetMapping(value = "/DeleteUser.do",produces = "text/html; charset=utf-8")
    public String DeleteUser(RentingUser rentingUser,HttpSession session){
        serviceAdmin.AdminDeleteUser(rentingUser,session);
        return "Admin-User";
    }

    //查询房间
    @PostMapping(value = "/QueryRoom.do",produces = "text/html; charset=utf-8")
    public String QueryRoom(Renting renting,HttpSession session){
        gain.GetRenting(renting,session);
        return "QueryRoom";
    }

    //查询用户
    @PostMapping(value = "/QueryUser.do",produces = "text/html; charset=utf-8")
    public String QueryUser(RentingUser user,HttpSession session){
        gain.GetUser(user,session);
        return "QueryUser";
    }
}
